<?php

namespace App\Models\Log;

use Illuminate\Database\Eloquent\Model;
use App\Models\Conf\Site;
use App\Models\Def\MainGamePlat;
use App\Models\Inf\Player;

class SiteScore extends Model
{

    public $table = 'log_site_score';

    const CREATED_AT = 'created_at';

    const UPDATED_AT = 'updated_at';

    //网站加分
    const SITE_PLAT_BONUS_POINT = 0;
    //管理员加分
    const ADMIN_SITE_PLAT_BONUS_POINT = 1;
    //网站平台转入
    const SITE_PLAT_TRANSFER_IN = 2;
    //网站平台转出
    const SITE_PLAT_TRANSFER_OUT = 3;
    //网站平台自动转入
    const SITE_PLAT_TRANSFER_IN_AUTO = 4;
    //平台互转转入
    const SITE_PLAT_MUTUAL_TRANSFER_IN = 5;
    //平台互转转出
    const SITE_PLAT_MUTUAL_TRANSFER_OUT = 6;

    //转账状态
    const TRANSFER_STATUS_SUCCESS = 1;
    const TRANSFER_STATUS_FAILED = 0;
    const TRANSFER_STATUS_UNKNOWN = -1;
    const TRANSFER_STATUS_CANCEL = 2;

    public $guarded = [];


    public static $rules = [];

    public function Site()
    {
        return $this->belongsTo(Site::class, 'site_id');
    }

    public function MainGamePlat()
    {
        return $this->belongsTo(MainGamePlat::class, 'main_game_plats_id', 'id');
    }

    public function Player()
    {
        return $this->belongsTo(Player::class, 'player_id', 'id');
    }

    public function earning()
    {
        return $this->hasOne(Earning::class,'site_score_id');
    }

    public function getOpType()
    {
        switch ($this->op) {
            case self::SITE_PLAT_BONUS_POINT:
                return '网站加分';
            case self::ADMIN_SITE_PLAT_BONUS_POINT:
                return '管理员加分';
            case self::SITE_PLAT_TRANSFER_IN:
                return '平台转入';
            case self::SITE_PLAT_TRANSFER_OUT:
                return '平台转出';
            case self::SITE_PLAT_TRANSFER_IN_AUTO:
                return '网站自动加分';
            case self::SITE_PLAT_MUTUAL_TRANSFER_IN:
                return '平台互转转入';
            case self::SITE_PLAT_MUTUAL_TRANSFER_OUT:
                return '平台互转转出';
        }
    }

    public function getStatus()
    {
        switch ($this->status) {
            case self::TRANSFER_STATUS_SUCCESS:
                return '成功';
            case self::TRANSFER_STATUS_FAILED:
                return '失败';
            case self::TRANSFER_STATUS_UNKNOWN:
                return '未知';
            case self::TRANSFER_STATUS_CANCEL:
                return '取消';
        }
    }
}
